# Python 2.6.4
# Project Euler, Problem 49
# Copyright 2010 Talha Zaman

from math import sqrt
def isprime(n):
    sn = sqrt(n)+1
    for i in range(2,sn+1):
        if n%i==0: return False
    return True
def isperm(x,y): return str(x).strip(str(y)) == str(y).strip(str(x)) == ""

p4 = [x for x in range(1000,10000) if isprime(x)]
for i in range(len(p4)):
    for j in [x for x in range(i) if isperm(p4[i], p4[x])]:
        next = 2*p4[i]-p4[j]
        if isperm(p4[i],next) and next in p4:
            print p4[j], p4[i], next
